<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="./vue.js"></script>
</head>

<body>
  <div id="app">
    <!-- Mustache语法 -->
    <h2>{{firstName+' '+name}}</h2>
    <!-- 计算属性语法 -->
    <h2>{{fullName1}}</h2>
    <!-- 计算属性的setter和getter -->
    <h2>{{fullName}}</h2>
  </div>

  <script>
    var vm = new Vue({
      el: '#app',
      data: {
        firstName: 'zhi',
        name: 'Taec'
      },
      computed: {
        fullName1: function () {
          return this.firstName + ' ' + this.name;
        }, //计算属性简写
        fullName: {
          set: function (newValue) { //要实现的话 这里一定要有参数
            console.log('______' + newValue);
            const names = newValue.split(' ');
            this.firstName = names[0];
            this.name = names[1];
          }, //我们不希望有set方法，所以一般会删除掉 删除后就是只读属性
          get: function () {
            return this.firstName + ' ' + this.name;
          }
        }
      }
    })
  </script>
</body>

</html>